<?php
//本文件做的事情： 爬若干页，图片保存到本地并产生新文件名，信息入库zfw.zfw_articles    文章内容还没采集
//要求php永不超时 只能用终端 不能用nginx apache，他们会超时
set_time_limit(0);

//绝对路径
include __DIR__ . '/function.php';
require __DIR__ . '/vendor/autoload.php';

use QL\QueryList;

//目标网页的格式:
//https://m-haoke-web.itheima.net/home



//采集
//对于图片的话，进行额外处理，先下载下来

$url = 'https://m-haoke-web.itheima.net/home';
//echo $url;

$html = http_request($url);
$html = '<html lang="en"><head><meta charset="utf-8"><link rel="shortcut icon" href="/favicon.ico"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><title>好客租房 | 移动Web</title><link href="/static/css/7.a00e9797.chunk.css" rel="stylesheet"><link href="/static/css/main.fbf1a77f.chunk.css" rel="stylesheet"><script charset="utf-8" src="/static/js/20.115f2e07.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/0.a0a5569b.chunk.css"><script charset="utf-8" src="/static/js/0.330b3469.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/6.dde02fe8.chunk.css"><script charset="utf-8" src="/static/js/6.78a966dc.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/18.f5cf6275.chunk.css"><script charset="utf-8" src="/static/js/18.b58025bf.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/1.92d35c6f.chunk.css"><script charset="utf-8" src="/static/js/1.1c67d079.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/3.264a246c.chunk.css"><script charset="utf-8" src="/static/js/3.6573b69f.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/8.5c78f02e.chunk.css"><script charset="utf-8" src="/static/js/8.6882a7bc.chunk.js"></script><link rel="stylesheet" type="text/css" href="/static/css/16.899cd2b4.chunk.css"><script charset="utf-8" src="/static/js/16.dd9424fa.chunk.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"><div class="App" style=""><div class="home"><div class="index"><div class="swiper"><div class="am-flexbox SearchHeader_searchBox__2-w3u  am-flexbox-align-center"><div class="am-flexbox SearchHeader_searchLeft__WSRBa am-flexbox-align-center"><div class="SearchHeader_location__1WGna"><span>北京</span><i class="iconfont icon-arrow"></i></div><div class="SearchHeader_searchForm__u-3Dp"><i class="iconfont icon-seach"></i><span>请输入小区或地址</span></div></div><i class="iconfont icon-map"></i></div><div class="slider am-carousel" style="position: relative; display: block; width: 100%; height: auto; box-sizing: border-box; visibility: visible;"><div class="slider-frame" style="position: relative; display: block; overflow: hidden; height: auto; margin: 0px; padding: 0px; transform: translate3d(0px, 0px, 0px); box-sizing: border-box;"><ul class="slider-list" style="transform: translate3d(-750px, 0px, 0px); position: relative; display: block; margin: 0px; padding: 0px; height: 212px; width: 1125px; cursor: inherit; box-sizing: border-box;"><li class="slider-slide" style="position: absolute; left: 1125px; top: 0px; display: inline-block; list-style-type: none; vertical-align: top; width: 375px; height: auto; box-sizing: border-box; margin: auto 0px;"><span style="display: inline-block; width: 100%; height: 212px;"><img src="https://api-haoke-web.itheima.net/img/swiper/1.png" alt="" style="width: 100%; vertical-align: top;"></span></li><li class="slider-slide" style="position: absolute; left: 375px; top: 0px; display: inline-block; list-style-type: none; vertical-align: top; width: 375px; height: auto; box-sizing: border-box; margin: auto 0px;"><span style="display: inline-block; width: 100%; height: 212px;"><img src="https://api-haoke-web.itheima.net/img/swiper/2.png" alt="" style="width: 100%; vertical-align: top;"></span></li><li class="slider-slide" style="position: absolute; left: 750px; top: 0px; display: inline-block; list-style-type: none; vertical-align: top; width: 375px; height: auto; box-sizing: border-box; margin: auto 0px;"><span style="display: inline-block; width: 100%; height: 212px;"><img src="https://api-haoke-web.itheima.net/img/swiper/3.png" alt="" style="width: 100%; vertical-align: top;"></span></li></ul></div><div class="slider-decorator-0" style="position: absolute; bottom: 0px; width: 100%; text-align: center;"><div class="am-carousel-wrap"><div class="am-carousel-wrap-dot"><span></span></div><div class="am-carousel-wrap-dot"><span></span></div><div class="am-carousel-wrap-dot am-carousel-wrap-dot-active"><span></span></div></div></div><style type="text/css">.slider-slide > img {width: 100%; display: block;}</style></div></div><div class="am-flexbox nav am-flexbox-align-center"><div class="am-flexbox-item"><img src="" alt=""><p>整租</p></div><div class="am-flexbox-item"><img src="" alt=""><p>合租</p></div><div class="am-flexbox-item"><img src="" alt=""><p>地图找房</p></div><div class="am-flexbox-item"><img src="" alt=""><p>去出租</p></div></div><div class="groups"><div class="am-flexbox groups-title am-flexbox-justify-between am-flexbox-align-center"><h3>租房小组</h3><span>更多</span></div><div class="am-grid"><div class="am-flexbox am-flexbox-justify-center am-flexbox-align-stretch"><div class="am-flexbox-item am-grid-item" style="width: 50%;"><div class="am-grid-item-content"><div class="am-flexbox grid-item am-flexbox-justify-between am-flexbox-align-center"><div class="desc"><h3>家住回龙观</h3><p>归属的感觉</p></div><img src="https://api-haoke-web.itheima.net/img/groups/1.png" alt=""></div></div></div><div class="am-flexbox-item am-grid-item" style="width: 50%;"><div class="am-grid-item-content"><div class="am-flexbox grid-item am-flexbox-justify-between am-flexbox-align-center"><div class="desc"><h3>宜居四五环</h3><p>大都市生活</p></div><img src="https://api-haoke-web.itheima.net/img/groups/2.png" alt=""></div></div></div></div><div class="am-flexbox am-flexbox-justify-center am-flexbox-align-stretch"><div class="am-flexbox-item am-grid-item" style="width: 50%;"><div class="am-grid-item-content"><div class="am-flexbox grid-item am-flexbox-justify-between am-flexbox-align-center"><div class="desc"><h3>喧嚣三里屯</h3><p>繁华的背后</p></div><img src="https://api-haoke-web.itheima.net/img/groups/3.png" alt=""></div></div></div><div class="am-flexbox-item am-grid-item" style="width: 50%;"><div class="am-grid-item-content"><div class="am-flexbox grid-item am-flexbox-justify-between am-flexbox-align-center"><div class="desc"><h3>比邻十号线</h3><p>地铁心连心</p></div><img src="https://api-haoke-web.itheima.net/img/groups/4.png" alt=""></div></div></div></div></div></div><div class="news"><h3 class="group-title">最新资讯</h3><div class="am-wingblank am-wingblank-md"><div class="news-item"><div class="imgwrap"><img class="img" src="https://api-haoke-web.itheima.net/img/news/1.png" alt=""></div><div class="am-flexbox content am-flexbox-dir-column am-flexbox-justify-between am-flexbox-align-center"><h3 class="title">置业选择 | 安贞西里 三室一厅 河间的古雅别院</h3><div class="am-flexbox info am-flexbox-justify-between am-flexbox-align-center"><span>新华网</span><span>两天前</span></div></div></div><div class="news-item"><div class="imgwrap"><img class="img" src="https://api-haoke-web.itheima.net/img/news/2.png" alt=""></div><div class="am-flexbox content am-flexbox-dir-column am-flexbox-justify-between am-flexbox-align-center"><h3 class="title">置业佳选 | 大理王宫 苍山洱海间的古雅别院</h3><div class="am-flexbox info am-flexbox-justify-between am-flexbox-align-center"><span>新华网</span><span>一周前</span></div></div></div><div class="news-item"><div class="imgwrap"><img class="img" src="https://api-haoke-web.itheima.net/img/news/3.png" alt=""></div><div class="am-flexbox content am-flexbox-dir-column am-flexbox-justify-between am-flexbox-align-center"><h3 class="title">置业选择 | 安居小屋 花园洋房 清新别野</h3><div class="am-flexbox info am-flexbox-justify-between am-flexbox-align-center"><span>新华网</span><span>一周前</span></div></div></div></div></div></div><div class="tabbar"><div class="am-tab-bar"><div class="am-tabs am-tabs-horizontal am-tabs-bottom"><div class="am-tabs-tab-bar-wrap"><div class="am-tab-bar-bar" style="background-color: white;"><div class="am-tab-bar-tab"><div class="am-tab-bar-tab-icon" style="color: rgb(33, 185, 122);"><i class="iconfont icon-ind"></i></div><p class="am-tab-bar-tab-title" style="color: rgb(33, 185, 122);">首页</p></div><div class="am-tab-bar-tab"><div class="am-tab-bar-tab-icon" style="color: rgb(136, 136, 136);"><i class="iconfont icon-findHouse"></i></div><p class="am-tab-bar-tab-title" style="color: rgb(136, 136, 136);">找房</p></div><div class="am-tab-bar-tab"><div class="am-tab-bar-tab-icon" style="color: rgb(136, 136, 136);"><i class="iconfont icon-my"></i></div><p class="am-tab-bar-tab-title" style="color: rgb(136, 136, 136);">我的</p></div></div></div></div></div></div></div></div></div><script src="https://api.map.baidu.com/api?v=3.0&amp;ak=V6QjTFDX6eNCd01nSig3NIfb7alYkzZu"></script><script type="text/javascript" src="https://api.map.baidu.com/getscript?v=3.0&amp;ak=V6QjTFDX6eNCd01nSig3NIfb7alYkzZu&amp;services=&amp;t=20210201100830"></script><script>!function(u){function e(e){for(var t,r,n=e[0],o=e[1],a=e[2],c=0,f=[];c<n.length;c++)r=n[c],s[r]&&f.push(s[r][0]),s[r]=0;for(t in o)Object.prototype.hasOwnProperty.call(o,t)&&(u[t]=o[t]);for(b&&b(e);f.length;)f.shift()();return d.push.apply(d,a||[]),i()}function i(){for(var e,t=0;t<d.length;t++){for(var r=d[t],n=!0,o=1;o<r.length;o++){var a=r[o];0!==s[a]&&(n=!1)}n&&(d.splice(t--,1),e=p(p.s=r[0]))}return e}var r={},l={5:0},s={5:0},d=[];function p(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return u[e].call(t.exports,t,t.exports,p),t.l=!0,t.exports}p.e=function(d){var e=[];l[d]?e.push(l[d]):0!==l[d]&&{0:1,1:1,2:1,3:1,6:1,8:1,10:1,11:1,12:1,13:1,14:1,15:1,16:1,17:1,18:1,19:1}[d]&&e.push(l[d]=new Promise(function(e,n){for(var t="static/css/"+({}[d]||d)+"."+{0:"a0a5569b",1:"92d35c6f",2:"c8c72bb3",3:"264a246c",6:"dde02fe8",8:"5c78f02e",9:"31d6cfe0",10:"f5775f8c",11:"7fd821d9",12:"ee8fcd06",13:"dadfee68",14:"dad5bec0",15:"030ac8be",16:"899cd2b4",17:"c2fd9ebd",18:"f5cf6275",19:"8e5fdf0f",20:"31d6cfe0"}[d]+".chunk.css",o=p.p+t,r=document.getElementsByTagName("link"),a=0;a<r.length;a++){var c=(u=r[a]).getAttribute("data-href")||u.getAttribute("href");if("stylesheet"===u.rel&&(c===t||c===o))return e()}var f=document.getElementsByTagName("style");for(a=0;a<f.length;a++){var u;if((c=(u=f[a]).getAttribute("data-href"))===t||c===o)return e()}var i=document.createElement("link");i.rel="stylesheet",i.type="text/css",i.onload=e,i.onerror=function(e){var t=e&&e.target&&e.target.src||o,r=new Error("Loading CSS chunk "+d+" failed.\n("+t+")");r.request=t,delete l[d],i.parentNode.removeChild(i),n(r)},i.href=o,document.getElementsByTagName("head")[0].appendChild(i)}).then(function(){l[d]=0}));var r=s[d];if(0!==r)if(r)e.push(r[2]);else{var t=new Promise(function(e,t){r=s[d]=[e,t]});e.push(r[2]=t);var n,a=document.createElement("script");a.charset="utf-8",a.timeout=120,p.nc&&a.setAttribute("nonce",p.nc),a.src=p.p+"static/js/"+({}[d]||d)+"."+{0:"330b3469",1:"1c67d079",2:"1f4cc6e0",3:"6573b69f",6:"78a966dc",8:"6882a7bc",9:"316ab611",10:"98ac7901",11:"57f28d1c",12:"b47c83aa",13:"50fc651b",14:"13abd14e",15:"397a2c81",16:"dd9424fa",17:"c3521839",18:"b58025bf",19:"6502b566",20:"115f2e07"}[d]+".chunk.js",n=function(e){a.onerror=a.onload=null,clearTimeout(c);var t=s[d];if(0!==t){if(t){var r=e&&("load"===e.type?"missing":e.type),n=e&&e.target&&e.target.src,o=new Error("Loading chunk "+d+" failed.\n("+r+": "+n+")");o.type=r,o.request=n,t[1](o)}s[d]=void 0}};var c=setTimeout(function(){n({type:"timeout",target:a})},12e4);a.onerror=a.onload=n,document.head.appendChild(a)}return Promise.all(e)},p.m=u,p.c=r,p.d=function(e,t,r){p.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},p.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},p.t=function(t,e){if(1&e&&(t=p(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(p.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)p.d(r,n,function(e){return t[e]}.bind(null,n));return r},p.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return p.d(t,"a",t),t},p.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p.p="/",p.oe=function(e){throw console.error(e),e};var t=window.webpackJsonp=window.webpackJsonp||[],n=t.push.bind(t);t.push=e,t=t.slice();for(var o=0;o<t.length;o++)e(t[o]);var b=n;i()}([])</script><script src="/static/js/7.de50a2c7.chunk.js"></script><script src="/static/js/main.54e858f9.chunk.js"></script></body></html>';
//$html = '<div class="App"><img src="aaaaasdfasfda"></div>';
//分析采集
$datalist = QueryList::Query($html, [ //这里头key名和数据库的字段保持了一致(偷懒)
//    "pic" => ['img', 'src','', function($item) {
//        //$item是 图片的url
//        //得到扩展名
//        $ext = pathinfo($item, PATHINFO_EXTENSION);
//        //生成唯一文件名
//        $filename = 'hkzf_' . md5($item). '_' . time(). '.' . $ext;
//        //生成的本地路径
//        $filepath = dirname(__DIR__) . '/public/uploads/spider/haokezufang/' . $filename;
//        //把$item的内容请求到，重命名到本地$filepath
//        file_put_contents($filepath, http_request($item));
//        //把存到数据库的pic字段内容返回， 可以在$datalist看到
//        return '/uploads/article/' . $filename;
//    }],
//    "title" => ['.item .text .LOGCLICK', 'src'],
//    "desn" => ['.item .text .summary', 'text'],
//    "url" => ['.item .text > a', 'href']
    "imgaaa" => ['.am-flexbox img', 'src'],
])->data;

var_dump($datalist);



